<?php
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/
/**
 * Class::BigDaddy::BigDaddyDisplay
 * Main classes for displaying BigDaddy data
 * @author Duleepa Wijayawardhana <dups@bioware.com>
 * @version 30/05/2006 11:38:06
 */
class BigDaddyDisplay extends BigDaddy
{
    public function __construct()
    {
        parent::__construct();
    }
    /**
     * void ShowServerModuleLine($aInfo, $nServerID)
     * Displays a line about server modules for a server
     *
     * Expecting array to contain
     * mon_currentlevel
     * serverID
     * moduleID
     * module_name
     * mon_lastreport
     * active
     * 
     * 
     */
    public function ShowServerModuleLine($aInfo, $nServerID, $sExtraButton = NULL)
    {
        ?>
        <tr valign="middle">
		<td class="lineitem">
		
		<?
		if ($aInfo["mon_currentlevel"]>0)
		{
		?>
			<img src="/images/warnlevel<?=$aInfo["mon_currentlevel"];?>.jpg" width="15" height="15" />
		<?
		}
		?>
		</td>
		<td class="lineitem">
        
        <?
        if ($aInfo["hostname"] != "")
        {
            echo '<a href="/index.html?page=ServerViewDetails&serverID='.$nServerID.'">'.$aInfo["hostname"]."</a> - ";
        }
        
        $sParam = trim(str_replace("[hostname]", "", $aInfo["parameters"]));
        
        if ($sParam != "")
        {
            $sParam = "(".$sParam.")";
        }
        
        ?>
        
		<a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerModEdit&serverID=<?=$nServerID;?>&modID=<?=$aInfo["moduleID"];?>&ID=<?=$aInfo["serverModuleID"];?>"><?=$aInfo["module_name"];?></a> <?=$sParam;?>
		</td>
		<td class="lineitem">
		<a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerModuleHistory&serverID=<?=$nServerID;?>&modID=<?=$aInfo["moduleID"];?>&ID=<?=$aInfo["serverModuleID"];?>"><img src="/images/data_history.jpg" border="0" align = "middle" /></a>
		<a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerModuleAudit&serverID=<?=$nServerID;?>&modID=<?=$aInfo["moduleID"];?>&ID=<?=$aInfo["serverModuleID"];?>"><img src="/images/audit.jpg" border="0" align = "middle" /></a> 
		ini: <a href="<?=$_SERVER["PHP_SELF"];?>?page=MonIniView&iniID=<?=$aInfo["iniID"];?>"><?=$aInfo["iniID"];?></a>
		</td>

		<td class="lineitem">
		last: 
			<?
			if ($aInfo["mon_lastreport"]==0)
			{
				echo "Never";
			}
			else
			{
				echo get_time_str($aInfo["mon_lastreport"], 2);
			};
			?>
		</td>
		<td class="lineitem" nowrap>
		<div class="buttons">
		
		<?
		if ($aInfo["active"]==1)
		{
		?>
			<span class="enabled">enabled</span>
			
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("server-enable"))
            {
		?>
			<a href="/server/query_servermod.php?action=enablemod&serverID=<?=$nServerID;?>&modID=<?=$aInfo["moduleID"];?>&ID=<?=$aInfo["serverModuleID"];?>">enable</a>
            
		<?
            }
            else
            {
                ?>
                <span class="dead">enable</span>
                <?
            }
		}
		?>
		
		<?
		if ($aInfo["active"]==0)
		{
		?>
			<span class="disabled">disabled</span>
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("server-disable"))
            {
		?>
			<a href="/server/query_servermod.php?action=disablemod&serverID=<?=$nServerID;?>&modID=<?=$aInfo["moduleID"];?>&ID=<?=$aInfo["serverModuleID"];?>">disable</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">disable</span>
                <?
            }
		}
		?>
		
		<?
		if ($aInfo["active"]==2)
		{
		?>
			<span class="delayed">delayed</span>
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("server-delay"))
            {
		?>
			<a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerModDelay&serverID=<?=$nServerID;?>&modID=<?=$aInfo["moduleID"];?>&ID=<?=$aInfo["serverModuleID"];?>">delay</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">delay</span>
                <?
            }
		}
		?>
		<?
        if ($this->IsUserAllowedByAction("server-remove"))
        {
            ?>
        <a href="/server/query_servermod.php?action=deletemod&serverID=<?=$nServerID;?>&modID=<?=$aInfo["moduleID"];?>&ID=<?=$aInfo["serverModuleID"];?>" onclick="javascript: return confirm('Delete this module: <?=$aInfo["module_name"];?> <?=$sParam;?>');">delete</a>
        <?
        }
            else
            {
                ?>
                <span class="dead">delete</span>
                <?
            }
            ?>
        
		<?=$sExtraButton;?>
		
        </div>
        </td>
        </tr>
        <?
    }
    /**
     * void ShowServerLine($aInfo)
     * Displays a line about a server
     * expecting $aInfo to be an array of:
     * 
     * mon_currentlevel
     * serverID
     * hostname
     * last_externalcheck
     * last_internalcheck
     * active
     *
     * @author Duleepa Wijayawardhana <dups@bioware.com>
     * @version 30/05/2006 15:33:59
     * 
     */
    public function ShowServerLine($aInfo)
    {
        
        ?>
        <tr valign="middle">
		<td class="lineitem">
		<?
		if ($aInfo["mon_currentlevel"]>0)
		{
		?>
			<img src="/images/warnlevel<?=$aInfo["mon_currentlevel"];?>.jpg" width="15" height="15" />
		<?
		}
		?>
		</td>
		<?
		if ($problemServer[$aInfo["serverID"]]==1)
		{
			$id="id=\"problem\"";
		}
		else
		{
			$id="";
		}
		?>
		<td class="lineitem" <?=$id;?> width="200">
        <a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerHistory&serverID=<?=$aInfo["serverID"];?>"><img src="/images/data_history.jpg" border="0" align = "middle" /></a>
        <a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerAudit&serverID=<?=$aInfo["serverID"];?>"><img src="/images/audit.jpg" border="0" align = "middle" /></a> 
		
		<a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerViewDetails&serverID=<?=$aInfo["serverID"];?>"><?=$aInfo["hostname"];?></a>
		</td>
		
		
		<td class="lineitem" width="200">
        <?
			
			if ($aInfo["last_externalcheck"]==0)
			{
				echo "Last Report: Never";
			}
			else
			{
				echo "Last Report: ".get_time_str($aInfo["last_externalcheck"], 2);
			}
		?>
		</td>
		<td class="lineitem" nowrap>
		<div class="buttons">
		
		<?
		if ($aInfo["active"]==1)
		{
		?>
			<span class="enabled">enable</span>
			
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("server-enable"))
            {
		?>
			<a href="/server/query_server.php?action=enableserver&serverID=<?=$aInfo["serverID"];?>">enable</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">enable</span>
                <?
            }
		}
		?>
		
		<?
		if ($aInfo["active"]==0)
		{
		?>
			<span class="disabled">disable</span>
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("server-disable"))
            {
		?>
			<a href="/server/query_server.php?action=disableserver&serverID=<?=$aInfo["serverID"];?>">disable</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">disable</span>
                <?
            }
		}
		?>
		
		<?
		if ($aInfo["active"]==2)
		{
		?>
			<span class="delayed">delayed</span>
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("server-delay"))
            {
		?>
			<a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerDelay&serverID=<?=$aInfo["serverID"];?>">delay</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">delay</span>
                <?
            }
		}
		?>
		<?
        if ($this->IsUserAllowedByAction("server-remove"))
        {
            ?>
        <a href="/server/query_server.php?action=deleteserver&serverID=<?=$aInfo["serverID"];?>" onclick="javascript: return confirm('Delete this server: <?=$aInfo["hostname"];?>');">delete</a>
        <?
        }
        else
            {
                ?>
                <span class="dead">delete</span>
                <?
            }
            ?>
        
        </div>
        </td>
        </tr>
        
        <?
    }
    /**
     * void ShowCronLine($aInfo)
     * Shows a line of information and actions for a Cron.
     *
     * Array $aInfo expects at least the following:
     * mon_currentlevel
     * cronID
     * filename
     * last_ranend
     * last_ranstart
     * active
     * ignoreMonitor
     *
     * @author Duleepa Wijayawardhana <dups@bioware.com>
     * @version 30/05/2006 16:22:13
     */
    public function ShowCronLine($aInfo)
    {
        ?>
        <tr valign="middle">
		<td class="lineitem">
		<?
		if ($aInfo["mon_currentlevel"]>0)
		{
		?>
			<img src="/images/warnlevel<?=$aInfo["mon_currentlevel"];?>.jpg" width="15" height="15" />
		<?
		}
		?>
		</td>
		<td class="lineitem" width="200">
		<a href="<?=$_SERVER["PHP_SELF"];?>?page=CronViewDetails&cronID=<?=$aInfo["cronID"];?>"><?=$aInfo["filename"];?></a>
		</td>

		<td class="lineitem" width="200">
        <a href="<?=$_SERVER["PHP_SELF"];?>?page=CronAudit&cronID=<?=$aInfo["cronID"];?>"><img src="/images/audit.jpg" border="0" align = "middle" /></a> 
		<?

			if ($aInfo["last_ranend"]==0 && $aInfo["last_ranstart"]==0)
			{
				echo "Last Run: Never";
			}
			elseif ($aInfo["last_ranend"]>0 && $this->IsUserAllowedByAction("cron-edit"))
			{
				?>
				<a href="/crontab/query_crontab.php?action=clearruninfo&cronID=<?=$aInfo["cronID"];?>" onclick="javascript: return confirm ('Clear Run Info For <?=$aInfo["filename"];?>?');">
				<?
				echo "Last Run End: ".get_time_str($aInfo["last_ranend"], 2);
				echo "</a>";
			}
			elseif ($aInfo["last_ranstart"]>0 && $this->IsUserAllowedByAction("cron-edit"))
			{
				?>
				<a href="/crontab/query_crontab.php?action=clearruninfo&cronID=<?=$aInfo["cronID"];?>" onclick="javascript: return confirm ('Clear Run Info For <?=$aInfo["filename"];?>?');">
				<?
				echo "Last Run Start: ".get_time_str($aInfo["last_ranstart"], 2);
				echo "</a>";
			}
            elseif ($aInfo["last_ranend"]>0)
            {
                echo "Last Run End: ".get_time_str($aInfo["last_ranend"], 2);  
            }
            elseif ($aInfo["last_ranstart"]>0)
            {
                echo "Last Run Start: ".get_time_str($aInfo["last_ranstart"], 2);
            }
            
		?>
		</td>
		<td class="lineitem" nowrap>
		<div class="buttons">

		<?
		if ($aInfo["active"]==1)
		{
		?>
			<span class="enabled">enable</span>

		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("cron-enable"))
            {
		?>
			<a href="/crontab/query_crontab.php?action=enablecron&cronID=<?=$aInfo["cronID"];?>">enable</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">enable</span>
                <?
            }
		}
		?>

		<?
		if ($aInfo["active"]==0)
		{
		?>
			<span class="disabled">disable</span>
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("cron-disable"))
            {
		?>
			<a href="/crontab/query_crontab.php?action=disablecron&cronID=<?=$aInfo["cronID"];?>">disable</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">disable</span>
                <?
            }
		}
		?>

		<?
		if ($aInfo["active"]==2)
		{
		?>
			<span class="delayed">delayed</span>
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("cron-delay"))
            {
		?>
			<a href="<?=$_SERVER["PHP_SELF"];?>?page=CronDelay&cronID=<?=$aInfo["cronID"];?>">delay</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">delay</span>
                <?
            }
		}
        if ($this->IsUserAllowedByAction("cron-remove"))
        {
		?>

        <a href="/crontab/query_crontab.php?action=deletecron&cronID=<?=$aInfo["cronID"];?>" onclick="javascript: return confirm('Delete this cronjob: <?=$aInfo["filename"];?>');">delete</a>
        <?
        }
        else
        {
            ?>
            <span class="dead">delay</span>
            <?
        }
        ?>
        </div>
        </td>
		<td class="lineitem" nowrap>
		<div class="buttons">
		<?
		if ($aInfo["ignoreMonitor"]==0)
		{
			?>
			<span class="enabled">monitor: enabled</span>
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("cron-mon-enable"))
            {
		?>
			<a href="/crontab/query_crontab.php?action=enablemoncron&cronID=<?=$aInfo["cronID"];?>">monitor: enable</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">monitor: enable</span>
                <?
            }
		}
		?>
		<?
		if ($aInfo["ignoreMonitor"]==1)
		{
		?>

			<span class="disabled">monitor: disabled</span>
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("cron-mon-disable"))
            {
		?>
			<a href="/crontab/query_crontab.php?action=disablemoncron&cronID=<?=$aInfo["cronID"];?>">monitor: disable</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">monitor: disable</span>
                <?
            }
		}
		?>

		</div>
		</td>
        </tr>
        <?
    }
	/**
     * void ShowServerGroupLine($aInfo)
     * Displays a line about a server
     * expecting $aInfo to be an array of:
     * 
     * mon_currentlevel
     * serverID
     * hostname
     * last_externalcheck
     * last_internalcheck
     * active
     *
     * @author Duleepa Wijayawardhana <dups@bioware.com>
     * @version 01/06/2006 18:07:13
     * 
     */
    public function ShowServerGroupLine($aInfo)
    {
        
        ?>
        <tr valign="middle">
		<td class="lineitem">
		<?
		if ($aInfo["mon_currentlevel"]>0)
		{
		?>
			<img src="/images/warnlevel<?=$aInfo["mon_currentlevel"];?>.jpg" width="15" height="15" />
		<?
		}
		?>
		</td>
		
		<td class="lineitem" <?=$id;?> width="200">
		<a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerGroupViewDetails&serverGroupID=<?=$aInfo["serverGroupID"];?>"><?=$aInfo["groupname"];?></a>
		</td>
        <td class="lineitem" nowrap>
        <a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerGroupHistory&serverGroupID=<?=$aInfo["serverGroupID"];?>"><img src="/images/data_history.jpg" border="0" align = "middle" /></a>
        <a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerGroupAudit&serverGroupID=<?=$aInfo["serverGroupID"];?>"><img src="/images/audit.jpg" border="0" align = "middle" /></a>
        </td>
		<td class="lineitem" nowrap>
		<div class="buttons">
		
		<?
		if ($aInfo["active"]==1)
		{
		?>
			<span class="enabled">enabled</span>
			
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("server-enable"))
            {
		?>
			<a href="/servergroup/query_servergroup.php?action=enableservergroup&serverGroupID=<?=$aInfo["serverGroupID"];?>">enable</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">enable</span>
                <?
            }
		}
		?>
		
		<?
		if ($aInfo["active"]==0)
		{
		?>
			<span class="disabled">disabled</span>
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("server-disable"))
            {
		?>
			<a href="/servergroup/query_servergroup.php?action=disableservergroup&serverGroupID=<?=$aInfo["serverGroupID"];?>">disable</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">disable</span>
                <?
            }
		}
		?>
		
		<?
		if ($aInfo["active"]==2)
		{
		?>
			<span class="delayed">delayed</span>
		<?
		}
		else
		{
            if ($this->IsUserAllowedByAction("server-delay"))
            {
		?>
			<a href="<?=$_SERVER["PHP_SELF"];?>?page=ServerGroupDelay&serverGroupID=<?=$aInfo["serverGroupID"];?>">delay</a>
		<?
            }
            else
            {
                ?>
                <span class="dead">delay</span>
                <?
            }
		}
		?>
		<?
        if ($this->IsUserAllowedByAction("server-remove"))
        {
            ?>
            <a href="/servergroup/query_servergroup.php?action=deleteservergroup&serverGroupID=<?=$aInfo["serverGroupID"];?>" onclick="javascript: return confirm('Delete this server group: <?=$aInfo["groupname"];?>');">delete</a>
            <?
        }
        else
        {
            ?>
            <span class="dead">delete</span>
            <?
        }
        ?>
        
        
        </div>
        </td>
        </tr>
        
        <?
    }
    /**
     * void ShowReportGroupLine($aInfo)
     * Displays a line about a server
     * expecting $aInfo to be an array of:
     * 
     * mon_currentlevel
     * serverID
     * hostname
     * last_externalcheck
     * last_internalcheck
     * active
     *
     * @author Duleepa Wijayawardhana <dups@bioware.com>
     * @version 01/06/2006 18:07:13
     * 
     */
    public function ShowReportGroupLine($aInfo)
    {
        
        ?>
        <tr valign="middle">
		<td class="lineitem" <?=$id;?> width="200">
        <a href="<?=$_SERVER["PHP_SELF"];?>?page=ReportGroupHistory&serverGroupID=<?=$aInfo["serverGroupID"];?>"><img src="/images/data_history.jpg" border="0" align = "middle" /></a>
        
		<a href="<?=$_SERVER["PHP_SELF"];?>?page=ReportGroupViewDetails&serverGroupID=<?=$aInfo["serverGroupID"];?>"><?=$aInfo["groupname"];?></a>
		</td>
        <td class="lineitem" nowrap>
		<div class="buttons">
		<a href="/reportgroup/query_reportgroup.php?action=deleteservergroup&serverGroupID=<?=$aInfo["serverGroupID"];?>" onclick="javascript: return confirm('Delete this report group: <?=$aInfo["groupname"];?>');">delete</a>
     
        </div>
        </td>
        </tr>
        
        <?
    }
}
?>
